export interface IMP3Query {
	_id?: string;
	key?: string;
	title?: string;
	album?: string;
	artist?: string;
	mediatype?: "AUDIO" | "VIDEO";
}

/**
 * 标准化用户 query 数据输入
 * @param inputQuery 用户客户端 query
 */
export function normalizeQuery(
	inputQuery: any,
	getAllParams = false
): IMP3Query {
	const { key, title, artist, album } = inputQuery;

	const mediatype: "AUDIO" | "VIDEO" = inputQuery.mediatype;

	if (getAllParams) {
		return {
			key: String(key),
			album: String(album),
			title: String(title),
			artist: String(artist),
			mediatype,
		};
	}

	if (key) {
		return { key: String(key) };
	}

	if (title) {
		return { title: String(title) };
	}

	if (artist) {
		return { artist: String(artist) };
	}

	if (album) {
		return { album: String(album) };
	}

	if (mediatype) {
		return { mediatype };
	}

	return {};
}
